import re

# s = 'hello world'
# result = re.match('hello', s)
# print(result)
# print(result.group())
# print(result.span())
#
# s2 = '1pythonsdhaihfih8python8994ad'
# result2 = re.search('python', s2)
# print(result2)
# print(result2.group())
# print(result2.span())
#
# result3 = re.findall('python', s2)
# print(result3)

# 匹配账号，只能有数字和字母组成，长度在6-10位
pattern1 = r'^[a-zA-Z0-9]{6,10}$'
msg1 = input('请输入账号：')
result1 = re.match(pattern1, msg1)
if result1:
    print('账号格式正确')
else:
    print('账号格式错误')

# 匹配QQ号，要求纯数字，长度在5-11位，第一位不能是0
pattern2 = r'^[1-9]\d{4,10}$'
msg2 = input('请输入QQ号：')
result2 = re.match(pattern2, msg2)
if result2:
    print('QQ号格式正确')
else:
    print('QQ号格式错误')

# 匹配邮箱地址，要求只允许qq,163,gmail格式的邮箱
pattern3 = r'^[a-zA-Z0-9]+@(qq|163|gmail)\.com$'
msg3 = input('请输入邮箱：')
result3 = re.match(pattern3, msg3)
if result3:
    print('邮箱格式正确')
else:
    print('邮箱格式错误')
